/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * @author Administrator
 * Date: 2010-7-8 上午09:27:43
 */
package com.ccxe.manage.util.help;

import java.util.List;
import java.util.Map;

/**
 * json转换器
 * 
 * @author wangyx
 * 
 */
public class JSON_Convertor {

	/**
	 * 将树数据源转换为json格式
	 * 
	 * @param list
	 * @return [{id:aa,pid;0,name:name1,url:url_ok},{id:bb,pid;1,name:name2,url:
	 *         url_none}]
	 */
	public String convertTreeListToJson(List<Map<?, ?>> list) {
		StringBuffer buff = new StringBuffer();
		if (list == null || list.isEmpty()) {
			return "[]";
		}

		buff.append("[");
		for (Map<?, ?> map : list) {
			buff.append("{id:\"" + map.get("ID") + "\"");
			buff.append(",");
			buff.append("pid:\"" + map.get("PID") + "\"");
			buff.append(",");
			buff.append("name:\"" + map.get("NAME") + "\"");
			buff.append(",");
			buff.append("url:\"" + map.get("URL") + "\"}");
			buff.append(",");
		}
		buff.deleteCharAt(buff.length() - 1) ;
		return buff.append("]").toString();
	}
}
